<template>
  <Modal
    title="添加"
    :value="value"
    :mask-closable="true"
    :footer-hide="true"
    @input="$emit('input', $event)"
  >
    <Form
      ref="formTybkQualifications"
      :model="formTybkQualifications"
      :rules="ruleValidate"
      label-position="right"
      :label-width="80"
    >

      <FormItem label="资质名称" prop="qualifications_name">
        <Input type="text" v-model="formTybkQualifications.qualifications_name" placeholder="资质名称"/>
      </FormItem>

      <FormItem>
        <Button type="primary" @click="handleSubmit('formTybkQualifications')">提交</Button>
        <Button @click="handleReset('formTybkQualifications')" style="margin-left: 8px">重置</Button>
      </FormItem>
    </Form>
  </Modal>
</template>
<script>
import { save } from '@/api/qualifications'
import { createModelObj } from '@/libs/util'

export default {
  name: 'Add',
  props: {
    value: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      formTybkQualifications: {

        id: ''
        ,
        qualifications_name: ''
        ,
        deleted: null
        ,
        create_time: ''
        ,
        modification_time: ''
        ,
        deletion_time: ''
      },
      ruleValidate: {
        qualifications_name: [
          { required: true, message: '该值不能为空', trigger: 'blur' },
          { type: 'string', max: 255, message: '长度最长为255', trigger: 'blur' }
        ]
        ,
      }
    }
  },
  methods: {
    handleSubmit (name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          save(Object.assign({}, createModelObj(this.formTybkQualifications, 'tybkQualifications'))).then(
            res => {
              if (res) {
                this.$emit('addRow', res.row)
                this.$emit('input', false)
                this.handleReset(name)
              }
            }
          )
        } else {
          this.$Message.error('验证失败!')
        }
      })
    },
    handleReset (name) {
      this.$refs[name].resetFields()
    }
  }
}
</script>
